package com.qf.student.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.student.dao.StudentMapper;
import com.qf.student.entity.Student;
import com.qf.student.response.R;
import com.qf.student.service.IStudentService;
import com.qf.student.vo.output.StudentInfoOutputVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2022-11-21
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {

    @Autowired
    private StudentMapper studentMapper;


    @Override
    public R getUpdateInfo(Integer userId) {
        StudentInfoOutputVo studentInfo = studentMapper.getUpdateInfo(userId);
        if (studentInfo == null) {
            return R.createFAIL("登录信息异常，请重新登录");
        }
        return R.createSuccess(studentInfo);
    }

    @Override
    public R updateInfo(Integer userId, Student student) {
        Student student1 = studentMapper.selectById(userId);
        if (student1 == null) {
            return R.createFAIL("登录信息有误，请重新登录");
        }
        //设置学生的 ID
        student.setStudentId(userId);
        if (studentMapper.updateById(student) > 0) {
            return R.createSuccess("信息更新成功");
        }
        return R.createFAIL("信息更新失败");
    }

}
